{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加测评</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="questionAdd" id="questionAdd" method="post" action="{:url('questionAdd')}">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属分类：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="cat_id" id="cat_id">
                                    <option value="">==请选择==</option>
                                    {if !empty($question_cat)}
                                    {foreach name="question_cat" item="vo"}
                                    <option value="{$vo.id}">{$vo.name}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" >
                            </div>
                        </div>

                        <!--                      <div class="hr-line-dashed"></div>-->

                        <!--                      <div class="form-group">-->
                        <!--                        <label class="col-sm-3 control-label">费用：</label>-->
                        <!--                        <div class="input-group col-sm-4">-->
                        <!--                          <input id="org_money" type="text" class="form-control" name="fee" >-->
                        <!--                        </div>-->
                        <!--                      </div>-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">描述：</label>
                            <div class="input-group col-sm-4">
                                <textarea id="goods_remark" type="text" class="form-control" name="question_remark" ></textarea>

                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">已测：</label>
                            <div class="input-group col-sm-4">
                                <input id="sale_num" type="text" class="form-control" name="cp_num">
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">多少人想测：</label>
                            <div class="input-group col-sm-4">
                                <input id="want_sale" type="text" class="form-control" name="want_sale">
                            </div>
                        </div>




                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">主图(建议尺寸比例1:1)：</label>
                            <div class="input-group col-sm-4">
                                <input type="hidden" id="data_photo" name="cover">
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                                <div id="imgPicker" style="float:left">选择文件</div>
                                <img id="img_data" class="img-circle" height="80px" width="80px" style="float:left;margin-left: 50px;margin-top: -10px;" src="/static/admin/images/head_default.gif"/>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label " for="myEditor">图文详情：</label>
                            <div class="input-group col-sm-9">
                                <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="question_content" style="width:90%" id="myEditor"></textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>




                        <!--                        <div class="hr-line-dashed"></div>-->
                        <!--                        <div class="form-group">-->
                        <!--                            <label class="col-sm-3 control-label">维度最高分：</label>-->
                        <!--                            <div class="input-group col-sm-4">-->
                        <!--                                <input id="wd_max_point" type="text" class="form-control" name="wd_max_point">-->
                        <!--                            </div>-->
                        <!--                        </div>-->
                        <!--                        <div class="hr-line-dashed"></div>-->
                        <!--                        <div class="form-group">-->
                        <!--                            <label class="col-sm-3 control-label">维度最低分：</label>-->
                        <!--                            <div class="input-group col-sm-4">-->
                        <!--                                <input id="wd_min_point" type="text" class="form-control" name="wd_min_point">-->
                        <!--                            </div>-->
                        <!--                        </div>-->

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">关键词：</label>
                            <div class="input-group col-sm-4">
                                <input id="keywords" type="text" class="form-control" name="keywords" placeholder="输入查询关键词" >

                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序：</label>
                            <div class="input-group col-sm-4">
                                <input id="sort" type="text" class="form-control" name="sort" placeholder="排序越小越靠前" >

                            </div>
                        </div>

                        <!--                        <div class="hr-line-dashed"></div>-->
                        <!--                        <div class="form-group">-->
                        <!--                            <label class="col-sm-3 control-label">是否区分性别：</label>-->
                        <!--                            <div class="col-sm-6">-->
                        <!--                                <div class="radio i-checks">-->
                        <!--                                    <input type="radio" name='is_sex' value="1" checked="checked"/>需要&nbsp;&nbsp;-->
                        <!--                                    <input type="radio" name='is_sex' value="0" />不需要-->
                        <!--                                </div>-->
                        <!--                            </div>-->
                        <!--                        </div>-->

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否首页推荐：</label>
                            <div class="col-sm-6">
                                <div class="radio i-checks">
                                    <input type="radio" name='is_home' value="1"/>是&nbsp;&nbsp;
                                    <input type="radio" name='is_home' value="0" checked="checked"/>否
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否上架：</label>
                            <div class="col-sm-6">
                                <div class="radio i-checks">
                                    <input type="radio" name='is_show' value="1" checked="checked"/>上架&nbsp;&nbsp;
                                    <input type="radio" name='is_show' value="-1" />下架
                                </div>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Upload/upload')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。
        multiple: false, //是否多文件
        fileSingleSizeLimit: 1024*1024, //文件大小 单位默认  b
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val('/uploads/images/'+data._raw);
            $("#img_data").attr('src', '/uploads/images/' + data._raw).show();
        }
    });


    //当validate不通过时，会以派送错误事件的形式通知
    uploader.on('error', function (type) {
        switch (type) {
            case 'Q_EXCEED_NUM_LIMIT':
                layer.msg('错误：上传文件数量过多！', {icon: 5,time:1500,shade: 0.1});
                break;
            case 'Q_EXCEED_SIZE_LIMIT':
                layer.msg('错误：文件总大小超出限制！', {icon: 5,time:1500,shade: 0.1});
                break;
            case 'F_EXCEED_SIZE':
                layer.msg('错误：文件大小超出限制！', {icon: 5,time:1500,shade: 0.1});
                break;
            case 'Q_TYPE_DENIED':
                layer.msg('错误：禁止上传该类型文件！', {icon: 5,time:1500,shade: 0.1});
                break;
            case 'F_DUPLICATE':
                layer.msg('错误：请勿重复上传该文件！', {icon: 5,time:1500,shade: 0.1});
                break;
            default:
                layer.msg('错误代码：' + type, {icon: 5,time:1500,shade: 0.1});
                break;
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
            '</div>' );
    });



    // 文件上传过程中创建进度条实时显示。
    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');

        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<p class="progress"><span></span></p>')
                .appendTo( $li )
                .find('span');
        }

        $percent.css( 'width', percentage * 100 + '%' );
    });


    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    // 完成上传完了，成功或者失败，先删除进度条。
    uploader.on( 'uploadComplete', function( file ) {
        $( '#'+file.id ).find('.progress').remove();
    });

    //提交
    $(function(){
        $('#questionAdd').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });



        function checkForm(){



            if( '' == $.trim($('#cat_id').val())){
                layer.msg('请选择类目',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            if( '' == $.trim($('#name').val())){
                layer.msg('请输入名称',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }



        }


        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('Ceping/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }
        }
    });


    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>